package edu.cmu.cs211.exprtree.tests;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

import org.junit.Test;
import static edu.cmu.cs211.exprtree.tests.ExpressionTestUtil.*;
public class DivideExpressionTest {


	  @Test
	  public void testCfold0()
	  {
	    cfoldtest("5/5", "1");
	    cfoldtest("5/x", "5/x");
	    cfoldtest("x/5", "x/5");
	  }
	  
	  @Test
	  public void testCfold4() {
		cfoldtest("-1/x", "-1/x");
		cfoldtest("x/(-1)", "-x");
		cfoldtest("(x+1)/-1.0", "-(x+1)");
		cfoldtest("(x/1)/(x/1)/(x/1)", "x/x/x");
	    cfoldtest("(5/5)/(5/5)", "1");
		cfoldtest("((x+1)/1)/(1)", "x+1");  
	    cfoldtest("(((x+1)/1)/(1/1))", "(x+1)");
	    cfoldtest("(1/1)/((x)/1)", "1/x");
	    cfoldtest("20/1/1/1/1/1/1/1/1/1/1", "20");
	  }
	  
		@Test
		public void evalNoVars() {
			/* Construct the variable map */
			Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
			
			/* test the evaluate function with no variables */
			ExpressionTestUtil.evaluatetest("10/5", "2", map);
			ExpressionTestUtil.evaluatetest("(10/5)/(5/5)", "2", map);
			ExpressionTestUtil.evaluatetest("20/1/1/1/1/1/1/1/1/1/1", "20", map);
		}
		
		@Test
		public void evalVars() {
			/* Construct the variable map (maybe we could do this dynamically in a loop for 
			 * a more "stressful" test?)
			 */
			Map<String, BigDecimal> map = new HashMap<String, BigDecimal>();
			map.put("x", new BigDecimal("2120590622"));
			
			/* test the evalaute function with the current variable mapping */
			ExpressionTestUtil.evaluatetest("x/5", "1", map);
			ExpressionTestUtil.evaluatetest("0/x", "0", map);
			ExpressionTestUtil.evaluatetest("0.0/x", "0.0", map);
			ExpressionTestUtil.evaluatetest("0.1/x", "0.02", map);
			ExpressionTestUtil.evaluatetest("x/1", "5", map);
			ExpressionTestUtil.evaluatetest("x/1.0", "5.0", map);
			ExpressionTestUtil.evaluatetest("x/0.1", "50", map);
			ExpressionTestUtil.evaluatetest("(0/1)/x", "0", map);
			ExpressionTestUtil.evaluatetest("x/(1/1)", "5", map);
			ExpressionTestUtil.evaluatetest("(0/1)/x", "0", map);
			ExpressionTestUtil.evaluatetest("x/(1/1)", "5", map);
			ExpressionTestUtil.evaluatetest("(x/1)/(1/1)", "5", map);
			ExpressionTestUtil.evaluatetest("(0/1)/(x/1)", "0", map);
		}
}
